require 'openssl'
require 'base64'

module Azure
  module DocumentDB
    class HMACEncoder
      def encode master_key, message
        begin
          key = Base64.strict_decode64 master_key
          #key = ActiveSupport::Base64.decode64(master_key)
          hmac = OpenSSL::HMAC.digest 'sha256', key, message.downcase
          Base64.strict_encode64(hmac)
          #ActiveSupport::Base64.encode64s(hmac.to_s)

        rescue ArgumentErrot => e
          Rails.logger.warn "data: #{e} , #{data}"  
          
        end
      end
    end
  end
end
